﻿

namespace Futuret.Logger.Extensions;

/// <summary>
///  Author: Riva
///  Date: 2023/7/11 15:34 
///  Description: 日志扩展
/// </summary>
public static class ServiceCollectionExtension
{
    public static void AddCloudLogger(this WebApplicationBuilder builder)
    {
        builder.Host.UseSerilog((context, configuration) =>
        {
            configuration.ReadFrom.Configuration(GetLoggerConfig());
        });
    }

    /// <summary>
    ///     Get logger Configs
    /// </summary>
    /// <returns></returns>
    internal static IConfigurationRoot GetLoggerConfig()
    {
        var options = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.json")
            .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json",
                true)
            .Build();

        return options;
    }
}
